package bean;

import android.database.Cursor;
import android.provider.MediaStore;

import java.io.Serializable;
import java.util.ArrayList;

public class VideoBean implements Serializable {
    private String title;
    private String data;
    private int time;
    private long size;

    //获取视频
    public static VideoBean getInstanceFromCursor(Cursor cursor){
        VideoBean bean = new VideoBean();
        if (cursor == null||cursor.getCount()==0){
            return bean;
        }
        bean.time = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.DURATION));
        bean.title = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.TITLE));
        bean.data = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
        bean.size = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.SIZE));
        return bean;
    }

    //获取集合（用于切换上下
    public static ArrayList<VideoBean>getBeanFormCursor(Cursor cursor){
        ArrayList<VideoBean> list = new ArrayList<>();
        cursor.moveToPosition(-1);//移动到第一行的前面，这样之后moveToNext可以全部读取
        while (cursor.moveToNext()){
            VideoBean bean = getInstanceFromCursor(cursor);
            list.add(bean);
        }
        return list;
    }


//toString
    @Override
    public String toString() {
        return "VideoBean{" +
                "title='" + title + '\'' +
                ", data='" + data + '\'' +
                ", time=" + time +
                ", size=" + size +
                '}';
    }

    //    get set
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

}
